package com.lanou.sinasports.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lanou.sinasports.R;
import com.lanou.sinasports.activity.DropDownActivity;
import com.lanou.sinasports.adapter.NewsAdapter;

/**
 * Created by dllo on 16/1/7.
 */
public class NewsFragment extends Fragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private NewsAdapter adapter;
    private ImageView imageView;
    private Context context;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_news,container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
           tabLayout= (TabLayout) view.findViewById(R.id.tl_news);
           viewPager= (ViewPager) view.findViewById(R.id.vp_news);
           imageView= (ImageView) view.findViewById(R.id.iv_drop_down);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        adapter=new NewsAdapter(getActivity().getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent(context, DropDownActivity.class);
                startActivity(intent);
            }
        });
    }
}
